const root = {
    val: "A",
    left: {
        val: "B",
        left: {
            val: "D",
        },
        right: {
            val: "E",
        },
    },
    right: {
        val: "C",
        right: {
            val: "F",
        },
    },
};

function levelOrder(root) {
    if (!root) {
        return
    }
    let queue = [root]
    let res = []
    while (queue.length) {
        const top = queue[0]
        res.push(top.val)
        if (top.left) {
            queue.push(top.left)
        }
        if (top.right) {
            queue.push(top.right)
        }
        queue.shift()
    }
    return res
}

console.log(levelOrder(root));